﻿using B.S.Databasic.Api.Wrter.Application.Command.Permission;
using B.S.Databasic.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Databasic.Api.Wrter.Controllers
{
    /// <summary>
    /// 权限控制器(写)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PermissionController : ControllerBase
    {
        private readonly IMediator mediator;

        public PermissionController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 新增权限方法
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询到的权限列表</returns>
        [HttpPost]
        [Authorize]
        public Task<ApiResult<int>> AddPermission(AddPermissionCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改权限方法
        /// </summary>
        /// <param name="request">命令</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回查询到的权限列表</returns>
        [HttpPut]
        [Authorize]
        public Task<ApiResult<int>> UpdatePermission(UpdatePermissionCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除权限方法
        /// </summary>
        /// <param name="request">命令</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回查询到的权限列表</returns>
        [HttpDelete]
        [Authorize]
        public Task<ApiResult<int>> DeletePermission([FromQuery] DeletePermissionCommand request)
        {
            return mediator.Send(request);
        }
    }
}
